package com.yanqu.road.server.cmd.decoration;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.decoration.DecorationProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_CHANGE_ROLE, desc = "修改形象")
public class ChangeRoleCmd extends AbstractCommand {

	private int headId;
	private int costumeId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		DecorationProto.ChangeRoleReqMsg reqMsg = DecorationProto.ChangeRoleReqMsg.parseFrom(packet.getBytes());
		headId = reqMsg.getHeadId();
		costumeId = reqMsg.getCostumeId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(PlayerModule.class).changeRole(headId, costumeId);
	}

	@Override
	public void sendData(GamePlayer player) {
		if (ret != 0) {
			DecorationProto.ChangeRoleRespMsg.Builder respMsg = DecorationProto.ChangeRoleRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_CHANGE_ROLE, respMsg);
		}
	}

}
